package cn.livingCloud.controller.core.front;

import cn.livingCloud.dto.front.FrontImageUploadDto;
import cn.livingCloud.service.ImageUploadFrontService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * Created by DingJie on 2016/6/8.
 */
@Controller
@RequestMapping("/front/image")
public class ImageUploadController {
    @Autowired
    @Qualifier("imageUploadFrontServiceImpl")
    private ImageUploadFrontService uploadService;

    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    @ResponseBody
    public String uploadImage(@Valid FrontImageUploadDto imageFile, BindingResult result) {
        if (result.hasErrors()) {
            return uploadService.buildErrorJson(imageFile);
        }
        return uploadService.saveUploadImage(imageFile);
    }
}
